<?php
session_start();

$frist=!count($_POST);

?>


<html>
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
    <link rel="stylesheet" href="style.css">
	<link rel="shortcut icon" href="1.png" type="image/x-icon" />
    <title>忘记密码</title>
	
	
	<script type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8"></script>  
<script src="https://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
<script src="https://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
<script src="https://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>

<script type="text/javascript">
	function randoms()
	{
		document.getElementById("username").value = "";
		document.getElementById("repassword").value = "";
		document.getElementById("password").value = "";
	}

	
	$().ready(function() {
	// 在键盘按下并释放及提交后验证提交表单
	$("#forgetform").validate({
	    rules: {
		  //密码是6位以上
	      password: {
	        required: true,
			minlength:6,
			maxlength:10,
	        chrnum: true
	      },
		  //验证密码
	      repassword: {
	        required: true,			
	        chrnum: true,
	        equalTo: "#password"
	      },
		 
	    
	    },
	    messages: {
	      password: {
	        required: "请输入密码",
			minlength: "请输入6~10位密码",
			maxlength:"请输入6~10位密码"
	      },
	      repassword: {
	        required: "请输入密码",
	        equalTo: "两次密码输入不一致"
	      },
	     
	    }
		});
	});
	
</script>
<style>
.error{
	color:red;
}
</style>
	
</head>
 
<body onload="randoms()">
    <?php
        if($frist){
            
        
        ?>
    <section>
        <!-- 背景颜色 -->
        <div class="color"></div>
        <div class="color"></div>
        <div class="color"></div>
        <div class="box">
            <!-- 背景圆 -->
           
            <div class="container">
                <div class="form">
                    <h2>忘记密码</h2>
                    <form id = "forgetform" action="forget.php" method="post" name = "form">
                        <div class="inputBox">
                            <input type="text" placeholder="用户名" name="id" id="id">
 
                        </div>
                
			<div class="inputBox">
                            <input type="password" placeholder="请输入6~10位密码" name="password" id="password">
                        </div>
			<div class="inputBox">
                            <input type="password" placeholder="再次输入密码" name="repassword" id="repassword">
                        </div>						
                        <div class="inputBox">
                            <input type="submit" value="修改">
 
                        </div>
                        <p class="forget">已有账户?<a href="login1.php">
                                点击登录
                            </a></p>
                        <p class="forget">没有账户?<a href="register.php">
                                注册
                            </a></p>
                    </form>
                </div>
            </div>
        </div>
    </section>
    <?php
        }else{
            header("content-type:html;charset=utf-8");
            $hostname="127.0.0.1";
            $username="root";
            $password="123456";
            $database="tpsc";
            $link=mysqli_connect($hostname, $username,
            $password, $database);
            mysqli_set_charset($link, "utf-8");
            $username = $_POST["username"];
            $password = $_POST["password"];
//            $mycode = $_POST["mycode"];
            $sql = "update  user set  password='$password' where username='username'";
            $res = mysqli_query($link,$sql);
            $arr = mysqli_fetch_assoc($res);
//            if($mycode != $_SESSION['captcha']){
//                echo "<script>alert('验证码错误');window.location.href='login.php'</script>";
//            }
            echo '$password='.$password."====";
            echo '$arr='.$arr."++++";
            echo 'arr[passwdor]'.$arr["passwd"];
           
//           
            
            
            
            if($arr){
               if($password == $arr["passwd"]){
                   echo "<script>alert('修改成功');window.location.href='index.php'</script>";
               }else{
                   echo "<script>alert('修改失败');window.location.href='forget.php'</script>";
               }
            }else{
                echo "<script>alert('用户名错误');window.location.href='forget.php'</script>";
            }
        }
        
        ?>
</body>
 
</html>
